//
//  CMDBUserProfileCell.swift
//  CMDB
//
//  Created by 曹桂祥 on 2017/5/6.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBUserProfileCell: CustomBaseCell {
    
    var nameLabel : UILabel!
    
    var profileContentLabel : UILabel!
    
    override func setupCell() {
        super.setupCell()
        
        backgroundColor = UIColor.whiteColor()
    }
    
    override func cellBuildSubViews() {
        super.cellBuildSubViews()
        
        nameLabel = UILabel.getInstance()
        
        let testStr = "护照有效期"
        
        let size    = testStr.suitToSize(MaxSize, fontSize: 14, lineSpacing: 1)
        
        nameLabel.font = CMDB_14_FONT
        
        nameLabel.frame = CGRect(x: KleftMargin, y: KleftMargin, width: size.width, height: size.height)
        
        nameLabel.textColor = word54Color
        
        contentView.addSubview(nameLabel)
        
        profileContentLabel = UILabel.getInstance()
        
        profileContentLabel.font = CMDB_14_FONT
        
        profileContentLabel.text = "小磊"
        
        profileContentLabel.frame = CGRect(x: CGRectGetMaxX(nameLabel.frame) + 20, y:KleftMargin , width: 200, height: 20)
        
        profileContentLabel.textColor = word87Color
        
        contentView.addSubview(profileContentLabel)
    }
    
    override func loadContent() {
        
        let contentData = cellData as! CMDBProfileModel
        
        nameLabel.text = contentData.profileName
        
        let profileContentCount = contentData.profileContent.count
        
        profileContentLabel.text = contentData.profileContent.first
        
        if profileContentCount > 1 {
            
            contentData.profileContent.removeAtIndex(0)
            
            for (index,content) in contentData.profileContent.enumerate() {
                
                let label = UILabel.getInstance()
                
                label.textColor = word87Color
                
                label.font = CMDB_14_FONT
                
                label.text = content
                
                label.frame = CGRect(x: CGRectGetMaxX(nameLabel.frame) + 20, y:KleftMargin + CGFloat(20 * (index + 1)) + CGFloat(20 * (index + 1)), width: 200, height: 20)
                
                contentView.addSubview(label)
 
            }
        }

        if contentData.cellHeight == 0 {

            layoutIfNeeded()

            contentData.cellHeight = CGFloat(profileContentCount * (20) + (profileContentCount - 1) * 20) + KleftMargin * 2
        }
    }
}
